package com.bite.blog.model;


import com.bite.blog.enums.ResponseCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Response<T> {
    private int code;
    private String errMsg;
    private T data;


    public static <T> Response<T> fail(int code, String errMsg, T data) {
        return new Response<T>(code, errMsg, data);
    }

    public static <T> Response<T> fail(String errMsg) {
        return Response.fail(ResponseCodeEnum.FAIL.getCode(), errMsg, null);
    }

    public static <T> Response<T> fail(int code,String errMsg) {
        return Response.fail(code, errMsg, null);
    }

    public static <T> Response<T> fail(String errMsg, T data) {
        return Response.fail(ResponseCodeEnum.FAIL.getCode(), errMsg, data);
    }

    public static <T> Response<T> noLogin() {
        return new Response<T>(ResponseCodeEnum.NO_LOGIN.getCode(), "用户未登录", null);
    }

    public static <T> Response<T> success(T data) {
        return new Response<T>(ResponseCodeEnum.SUCCESS.getCode(), "", data);
    }


}
